uniform extern texture ScreenTexture;
uniform extern float2 PlayerPosition;
uniform extern float AspectRatio;

sampler ScreenS = sampler_state
{
    Texture = <ScreenTexture>;    
};

// 1
// 3	1
// 6	4	1
// 10	6	3	1

// sum = 10 + 10 * 4 + 6 * 4 = 74

// 1
// 3	1
// 6	4	1
// 10	6	3	1

//	3	6	3
//	6	10	6
//	3	6	3

// sum = 3*4 + 4*6 + 10 = 46
// 10/46 = 0.2173913043478261
// 6/46 = 0.1304347826086957
// 3/46 = 0.0652173913043478

float4 Shadow(float2 coord: TEXCOORD0) : COLOR
{
	int count = 9;
	float size = 0.005;
	float2 dx = float2(size, 0.0);
	float2 dy = float2(0.0, size);
	float2 shadowPos = coord + (PlayerPosition - coord) * 0.02;

	float4 output = float4(0.0, 0.0, 0.0, 0.0);
	output += tex2D(ScreenS, shadowPos) * 0.2173913043478261;
	output += tex2D(ScreenS, shadowPos + dx) * 0.1304347826086957;
	output += tex2D(ScreenS, shadowPos + dx + dy) * 0.0652173913043478;
	output += tex2D(ScreenS, shadowPos + dx - dy) * 0.0652173913043478;
	output += tex2D(ScreenS, shadowPos - dx) * 0.1304347826086957;
	output += tex2D(ScreenS, shadowPos - dx + dy) * 0.0652173913043478;
	output += tex2D(ScreenS, shadowPos - dx - dy) * 0.0652173913043478;
	output += tex2D(ScreenS, shadowPos - dy) * 0.1304347826086957;
	output += tex2D(ScreenS, shadowPos + dy) * 0.1304347826086957;

	return float4(0.0, 0.0, 0.0, output.a);
}

technique Colorize
{
    pass ColorTransform
    {
        PixelShader = compile ps_2_0 Shadow();
    }
}
